import process from "process";
import * as step from "../../src/index"

async function runStep(): Promise<void> {
    const flowJobToken: string | undefined =
        process.env["FLOW_JOB_TOKEN"]

    if (flowJobToken == undefined) {
        const errMsg = 'missing FLOW_JOB_TOKEN';
        throw new Error(errMsg)
    }

    const mavenPrivateRepoCertificate = await step.certificate.getNewMavenPrivateRepoCertificate(flowJobToken)
    if (!mavenPrivateRepoCertificate ||
        !mavenPrivateRepoCertificate.mavenSettingsContent ||
        !mavenPrivateRepoCertificate.mavenSettingsContent.trim()) {
        const message = "maven private repo settings is empty";
        throw new Error(message)
    }

    step.info("======================================")
    step.info(mavenPrivateRepoCertificate.mavenSettingsContent)
    step.info("======================================")
}

runStep()
    .then(function () {
        step.success('run step successfully!')
    })
    .catch(function (err: Error) {
        step.error(err.message)
        process.exit(-1)
    })
